<template>
  <div class="mod-menu">
    <el-dialog
      title="选择单品"
      :append-to-body="true"
      :visible.sync="visible"
      width="60%"
      :before-close="closeGoodsDialog"
    >
      <el-form :inline="true" :model="pamars">
        <el-form-item label="">
          <el-input
            v-model="pamars.title"
            placeholder="单品名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">查询</el-button>
        </el-form-item>
      </el-form>
      <span class="textWorning">提示：点击单品即选中</span>
      <el-table
        :data="dataList"
        row-key="Id"
        border
        style="width: 100%; "
        @row-click="rowClickSingle"
      >
        <el-table-column prop="title" align="center" label="单品名称">
        </el-table-column>
        <el-table-column prop="code" align="center" label="单品编码">
        </el-table-column>
        <el-table-column prop="unit" align="center" label="单品单位">
        </el-table-column>
        <el-table-column
          prop="goods_group_name"
          align="center"
          label="单品分组"
        >
        </el-table-column>
        <el-table-column prop="able_stock" align="center" label="库存">
        </el-table-column>
      </el-table>

      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pamars.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pamars.limit"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
      ></el-pagination>
    </el-dialog>
  </div>
</template>

<script>
import seviceApi from '@/api/serviceApi.js'
export default {
  data() {
    return {
      dataForm: {},
      visible: false,
      pamars: {
        page: 1,
        added: 1,
        limit: 10,
        mobile: '',
        shop_name: ''
      },
      totalPage: 0,
      dataList: [],
      dataListLoading: false,
      addOrUpdateVisible: false, // 添加，编辑
      outPutOrInPut: false // 出入库
    }
  },

  mounted() {
    this.getList()
  },
  methods: {
    init() {
      this.visible = true
    },
    closeGoodsDialog() {
      this.$emit('closeGoodsDialog')
    },
    rowClickSingle(val) {
      this.$emit('singleShowOnchange', val)
    },
    getList() {
      seviceApi.getSinglegoodsList(this.pamars).then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.page.list
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pamars.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pamars.page = val
      this.getList()
    },
    // 查询
    getDataList() {
      this.getList()
    }
  }
}
</script>
